package com.jeomo.base.starter.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.util.Objects;

/**
 * <h3>jeomo</h3>
 * <p>继承于Entity,但是如果你的Entity主键是code,则可以继承这个类，可以免去重写equals和hashcode等方法</p>
 *
 * @author : qibotian
 * @date : 2020-10-22 11:27
 **/
public class BaseCodeEntity extends BaseEntity {

    @TableId(value = "code", type = IdType.ASSIGN_ID)
    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        BaseCodeEntity that = (BaseCodeEntity) o;
        return Objects.equals(code, that.code);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), code);
    }
}
